package com.acme.task3;

/**
 * Class used to test arrays
 * @author S.Zhidkov
 *
 */
public class Task3Arrays {

    // array length
    private static final int ARRAY_LENGTH = 50;

	public static void main(String[] args) {
		for (int i = 1; i <= 50; i++) {
			if (i%3 == 0) {
			    System.out.println("Number " + i + " a multiple of 3");
			}
		}

		// Find average of array elements
		double [] array = new double[ARRAY_LENGTH];
		for (int i = 0; i < array.length; i++) {
		    array[i] = i + 1;
		}

		// print average
		System.out.println("Average of array elements = " + avg(array));

	}

	/**
	 * Method return arithmetic average from all elements of the array
	 * @param array from that elements find arithmetic average
	 * @return arithmetic average or NaN if array length == 0
	 */
	public static double avg(double [] array) {
	    double sum = 0;
	    for (double num : array) {
	        sum += num;
	    }

	    // if 'array.length == 0' returns NaN
	    return sum/array.length;
	}
}
